package com.football.service;

import okhttp3.*;
import top.hserver.core.ioc.annotation.Autowired;
import top.hserver.core.ioc.annotation.Bean;

import java.io.IOException;

@Bean
public class HttpService {


  @Autowired
  private OkHttpClient client;

  private final String url = "http://sport.ttyingqiu.com/sportdata/f";

  private static final MediaType JSON = MediaType.parse("application/json; charset=utf-8");

  public String post(String json) throws IOException {
    RequestBody body = RequestBody.create(JSON, json);
    Request request = new Request.Builder()
      .url(url)
      .post(body)
      .build();
    Response response = client.newCall(request).execute();
    return response.body().string();
  }
}